import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login'
import Home from '../components/Home'
import Welcome from '../components/Welcome'
// 系统组件
import SystemUser from '../components/system/User.vue'
import SystemRole from '../components/system/Role.vue'
import SystemMenu from '../components/system/Menu.vue'
// 错误信息

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      { path: '/welcome', component: Welcome },
      { path: '/system/user', component: SystemUser },
      { path: '/system/role', component: SystemRole },
      { path: '/system/menu', component: SystemMenu },
      // test
      { path: '/task/receiver/pending/list', component: SystemMenu },
      { path: '/task/receiver/done/list', component: SystemMenu },
      { path: '/task/receiver/delay/list', component: SystemMenu },
      { path: '/task/receiver/list', component: SystemMenu },
      { path: '/workplan/list', component: SystemMenu }
    ]
  }
]

const router = new VueRouter({
  routes
})

// 解决两次访问相同路由地址报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

// to 要访问的
// from 来源
// next 放行。
// next() 放行 next('/login') 跳转
// router.beforeEach((to, from, next) => {
//   // 登录页，放行
//   if (to.path === '/login') {
//     return next()
//   } else {
//     // FIXME 这里要走请求校验，但是我不会走...
//     const resu = this.$axios.post('login')
//     console.log(resu)
//   }
// })

export default router
